package com.yfbao.horizon.utils;

import java.util.regex.Pattern;

public class PassWordCheck {

    public static final int PASSWORD_MAX = 50;
    public static boolean checkPasswordStrengthForCustom(String password, Integer minLen,Boolean numberEnable,Boolean specialEnable,Boolean upperAndLowerEnable){
        if(password.length()<minLen || password.length()>PASSWORD_MAX){
            System.out.println("密码长度不合规");
            return false;
        }
        if(upperAndLowerEnable){
            if(!Pattern.matches(".*[a-z].*",password) || !Pattern.matches(".*[A-Z].*",password)){
                System.out.println("不包大小写");
                return false;
            }
        }
        if(numberEnable){
            if(!Pattern.matches(".*\\d.*",password)){
                System.out.println("不包含数字");
                return false;
            }
        }
        if(specialEnable){
            //~`!@#$%^&*()_+-=[]{}\|:;'",.<>?/
            if(!Pattern.matches(".*[~`!@#$%^&*()_+-=\\[\\]{}|\\\\;:'\",.<>?/].*",password)){
                System.out.println("不包含要求特殊字符");
                return false;
            }
        }
        return true;
    }
}
